home *** CD-ROM | disk | FTP | other *** search
/ Leonardo the Inventor / Leonardo The Inventor (93026)(Broderbund)(Riverdeep)(2004).iso / LEOWINMV / DATABASE.DIR / 00083_Script_DB SCROLL < prev    next >
Text File  |  1996-03-28  |  8KB  |  224 lines

  1. -- ---------------------------------------------------------------
  2. -- HANDLERS scrollArea, updateScrollBar, and updateBrowser are used
  3. -- when the user scrolls by clicking the square in the scroll bar.
  4. -- ---------------------------------------------------------------
  5.  
  6. -- ---------------------------------------------------------------
  7. -- Handler scrollArea moves the scroll square and updates the text
  8. -- in the browser when the user scrolls by clicking the square in
  9. -- the scroll bar.
  10.  
  11. on scrollArea  clickV
  12.   global browserTopLine, browserScroll
  13.   
  14.   --  cleardatabase
  15.   unhiliteClickedTopic
  16.   
  17.   updateScrollArea(clickV)
  18.   updateBrowser
  19.   updateStage
  20.   
  21.   repeat while the mouseDown 
  22.     scrollArea(the mouseV)
  23.   end repeat
  24. end
  25.  
  26. -- --------------------------------------------------------------
  27. -- Handler resetScrollArea moves the scroll square when the user
  28. -- scrolls by clicking the square in the scroll bar.
  29.  
  30. on resetScrollArea 
  31.   global origScrollPos, browserScroll
  32.   
  33.   set the locV of sprite browserScroll = origScrollPos
  34.   -- updateStage done elsewhere
  35. end
  36.  
  37. -- --------------------------------------------------------------
  38. -- Handler updateScrollArea moves the scroll square when the user
  39. -- scrolls by clicking the square in the scroll bar.
  40.  
  41. on updateScrollArea clickV
  42.   global browserScroll
  43.   
  44.   -- the locV of sprite scrollSprite will be constrained by 'the
  45.   -- constraint of sprite scrollSprite' set in initializeData.
  46.   
  47.   set the locV of sprite browserScroll = clickV
  48.   -- updateStage done elsewhere
  49. end
  50.  
  51. -- --------------------------------------------------------------
  52. -- Handler updateBrowser updates the text in the browser when the
  53. -- user scrolls by clicking the square in the scroll bar.
  54.  
  55. on updateBrowser
  56.   global  constraintScrollBar, browserTopics, numVisibleTopics, browserTopLine
  57.   global browserScroll, numLinesPerBrowserEntry
  58.   
  59.   set scrollHeight = the height of sprite constraintScrollBar
  60.   set V = the locV of sprite browserScroll - the top of sprite constraintScrollBar
  61.   
  62.   set numTopics = the number of lines in browserTopics
  63.   set browserTopLine = integer (V * numTopics / scrollHeight)
  64.   
  65.   set lastLine = numTopics - numVisibleTopics
  66.   if (browsertopline >= lastLine) then
  67.     set browserTopLine = lastLine
  68.   end if
  69.   
  70.   if (browserTopLine = 0) then 
  71.     set browserTopLine = 1
  72.   end if
  73.   
  74.   setBrowserText
  75. end
  76.  
  77. -- ---------------------------------------------------------------
  78. -- Handler scrollBrowser is used when the user scrolls by clicking
  79. -- the up and down arrows of the browser. It (1) clears the stage
  80. -- from any info pertaining to the previous topic, scrolls the text
  81. -- in the browser, (2) scrolls the browser in the given direction
  82. -- (1 = scrollDown, -1 = scrollUp).
  83. -- The parameter clickedSprite is passed to make sure that the mouse
  84. -- has not moved when scrolling continues.
  85.  
  86. on scrollBrowser clickedSprite, direction
  87.   global browserTopLine, browserScroll, numVisibleTopics, browserTopics, numVisibleLines
  88.   
  89.   --  clearDatabase
  90.   unhiliteClickedTopic
  91.   set numLines = the number of lines in browserTopics - numVisibleLines
  92.   
  93.   scroll(clickedSprite, direction, numLines)
  94.   
  95.   repeat while (the mouseDown)
  96.     if (the mouseCast = the castNum of sprite clickedSprite) then
  97.       scroll(clickedSprite, direction, numLines)
  98.     end if
  99.   end repeat
  100. end
  101.  
  102. -- ---------------------------------------------------------------
  103. -- Handler scroll:(1) updates the topLine of the given field to be
  104. -- scrolled (browser or text) (2) moves the given scroll square to
  105. -- correspond to the text and (3) updates the text in the given field.
  106. -- The handler takes the following parameters:
  107. -- (A) clickedSprite (the original sprite that was clicked to start the 
  108. -- scrolling. This is to make sure that if the mouse remains down
  109. -- but moves from over a scrolling arrow, the text does not continue
  110. -- scrolling)
  111. -- (B) direction (1 = scrollDown, -1 = scrollUp)
  112. -- (C) numLines (the number of lines in the text to be browsed)
  113.  
  114. on scroll clickedSprite, direction, numLines
  115.   global browserTopLine, browserScroll, numVisibleTopics, browserTopics
  116.   
  117.   set browserTopLine = updateBrowserTopLine(direction, numLines)
  118.   moveScrollSquareToMatchText
  119.   
  120.   setBrowserText
  121. end
  122.  
  123. -- ---------------------------------------------------------------
  124. -- Handler updateBrowserTopLine 
  125.  
  126. on updateBrowserTopLine amount, max
  127.   global browserTopLine
  128.   
  129.   set browserTopLine = validNum(browserTopLine + amount, 1, max)
  130.   return browserTopLine
  131. end
  132.  
  133. -- ---------------------------------------------------------------
  134. -- Handler moveScrollSquareToMatchText is called from scroll (which
  135. -- is called when the user clicks the up or down arrows to scroll
  136. -- the browser).  It moves the scrollSquare (in sprite
  137. -- browserScroll) to match the change in the text.
  138.  
  139. on  moveScrollSquareToMatchText
  140.   global  constraintScrollBar, browserTopics, browserTopLine, numVisibleLines
  141.   global browserScroll
  142.   
  143.   set scrollHeight = the height of sprite constraintScrollBar
  144.   set nonZeroInteger = (the number of lines in browserTopics - numVisibleLines )
  145.   
  146.   if (nonZeroInteger = 0) then set nonZeroInteger = -1
  147.   
  148.   set V = ((browserTopLine) * scrollHeight) / (nonZeroInteger) + (the top of sprite constraintScrollBar)
  149.   
  150.   if (browserTopLine = 1) then 
  151.     set V = the top of sprite constraintScrollBar
  152.   end if
  153.   
  154.   set the locV of sprite browserScroll = V
  155.   updateStage
  156. end
  157.  
  158. -- ---------------------------------------------------------------
  159. -- Handler setBrowserText sets the text of the onstage browser
  160. -- (field "browser").
  161.  
  162. on setBrowserText
  163.   global browserTopLine, numVisibleTopics, browserTopics, numLinesPerBrowserEntry
  164.   global numBrowsers, currentBrowser, browserTopics, numVisibleLines
  165.   
  166.   set lastLine = numVisibleLines + browserTopLine - 1
  167.   
  168.   set browserText = line browserTopLine to lastLine of browserTopics
  169.   
  170.   set the text of cast "browser" = browserText
  171.   put EMPTY into line (lastLine + 1) of cast "browser"
  172. end
  173.  
  174. -- ---------------------------------------------------------------
  175. -- Handler setFieldText sets the text of the given field ("browser" or
  176. -- "Displayed Text")
  177. -- make this unique to the browser field
  178.  
  179. on setFieldText scrollField, topLine, numVisibleLines, allText
  180.   set the text of cast scrollField = line topLine to (numVisibleLines + topLine - 1) of allText
  181.   put EMPTY into line (numVisibleLines+1) of cast scrollField
  182. end
  183.  
  184. -- ---------------------------------------------------------------
  185. -- Handler displayKeyLineAtTop is used when the user scrolls by
  186. -- typing a key.  It displays at the top of the onstage field
  187. -- "browser" the first line of field "browserTopics" that begins
  188. -- with the letter the user typed.
  189.  
  190. on displayKeyLineAtTop
  191.   global numberTopics, browserTopics, browserTopLine, numVisibleTopics
  192.   global browserScroll, alphabetTopicStarts
  193.   global numVisibleLines, mode
  194.   
  195.   --  clearDatabase
  196.   unhiliteClickedTopic
  197.   set whichKey = the key
  198.   set charNumber = charToNum(whichKey)
  199.   set numLines = (the number of lines in browserTopics) - numVisibleLines
  200.   
  201.   if (charNumber = 30) then --  up arrow key
  202.     scroll(0, -1, numLines)
  203.   else if (charNumber = 31) then -- down arrow key
  204.     scroll(0, 1, numLines)
  205.   else if ("abcdefghijklmnopqrstuvwxyz" contains whichKey) then
  206.     set charNumber = charToNum(convertToLower(whichKey))
  207.     
  208.     -- get the line number of the first browser line beginning with the key pressed
  209.     if (mode = "index") then
  210.       set browserTopLine = value(item 2 of line (charNumber - 96) of alphabetTopicStarts)
  211.     else if (mode = "media") then
  212.       set browserTopLine = value(item 3 of line (charNumber - 96) of alphabetTopicStarts)
  213.     end if
  214.     
  215.     set NumRemain = numberTopics - (browserTopLine)
  216.     --   what is the following if statment for?
  217.     --    if (NumRemain < numVisibleTopics) then
  218.     --      set browserTopLine = numberTopics + 1 - numVisibleTopics
  219.     --    end if
  220.     
  221.     setBrowserText
  222.     moveScrollSquareToMatchText
  223.   end if
  224. end